package medium;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 排序+双指针
 */
public class T18 {
    public static void main(String[] args) {
        fourSum(new int[]{1000000000,1000000000,1000000000,1000000000}, -294967296);
        System.out.println(1000000000L+1000000000+1000000000+1000000000);
    }
    public static List<List<Integer>> fourSum(int[] nums, int target) {
        Arrays.sort(nums);
        ArrayList<List<Integer>> result = new ArrayList<>();
        for (int a = 0; a < nums.length - 3; a++) {
            if (a > 0 && nums[a] == nums[a - 1]) continue;
            for (int b = a + 1; b < nums.length - 2; b++) {
                if (b > a + 1 && nums[b] == nums[b - 1]) continue;
                for (int c = b + 1; c < nums.length - 1; c++) {
                    if (c > b + 1 && nums[c] == nums[c - 1]) continue;
                    for (int d = nums.length - 1; d > c; d--) {
                        if (d < nums.length - 1 && nums[d] == nums[d + 1]) {
                            continue;
                        }
                        if (((long) nums[a] + nums[b] + nums[c] + nums[d]) == target) {
                            List<Integer> list = new ArrayList<>();
                            list.add(nums[a]);
                            list.add(nums[b]);
                            list.add(nums[c]);
                            list.add(nums[d]);
                            result.add(list);
                        }
                    }
                }
            }
        }
        return result;
    }
}
